mkdir -p sources/manpages/

# 都是 .gz 文件
MANPAGES=`find /usr/share/man/man{1,2,3,4,5,6,7} -type f`

for pageFile in $MANPAGES;
do
    # echo $pageFile;
    txtFile=${pageFile//\//-};
    txtFile=sources/manpages/${txtFile:15:-3}.txt;
    if [ -f $txtFile ]; then continue; fi;
    # echo $txtFile;
    pageCategory=${pageFile:18:1};
    fileName=$(basename $pageFile);
    # pageName=${fileName%%.*};
    # pageName=$(basename -s ".$pageCategory.gz" $pageFile);
    pageName=${fileName%.*};
    pageName=${pageName%.*};
    echo $pageCategory / $pageName;
    # cat $pageFile | gzip -d | groff -t -e -mandoc -Tascii | col -bx > $txtFile;
    man --nh $pageCategory $pageName | col -bx > $txtFile;
done
